<template>
  <el-row>
    <!-- 查询条件 -->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;height:46px">
      <el-form :inline="true">
        <el-form-item>
          <el-input v-model="loginNameSearch" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="userNameSearch" placeholder="姓名"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="phoneSearch" placeholder="手机号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="search" size="small" style="line-height:14px">查询</el-button>
        </el-form-item>
        <el-form-item class="button-align">
          <el-button type="danger" @click="batchDelete" :disabled="this.sels.length===0" size="small">批量删除</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-table :data="accountList" v-loading="listLoading" @selection-change="selsChange" border
              style="width: 100%; font-size: 12px;" row-class-name="tabRow">
      <el-table-column type="selection"></el-table-column>
      <el-table-column align="center" prop="loginName" label="用户名"></el-table-column>
      <el-table-column align="center" prop="nickName" label="昵称"></el-table-column>
      <el-table-column align="center" prop="userName" label="姓名"></el-table-column>
      <el-table-column align="center" prop="phone" label="手机号"></el-table-column>
      <el-table-column align="center" prop="mail" label="邮箱"></el-table-column>
      <el-table-column align="center" :formatter="createTimeStr" label="注册时间"></el-table-column>
      <el-table-column align="center" width="150" label="操作">
        <template scope="scope">
          <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="24" class="toolbar" style="margin-top: 15px;" v-show="!listLoading">
      <el-pagination id="pagination" layout="total, sizes, prev, pager, next, jumper" :page-sizes="[10, 20, 30]"
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
      </el-pagination>
    </el-col>
  </el-row>
</template>

<script type="text/ecmascript-6">
  import {sessionOut} from '../../smartlight/common/js/util.js'
  export default{
    data () {
      return {
        total: 2,
        page: 1,
        pageSize: 10,
        passengerList: [],
        count: 0,
        sels: [], // 列表选中列
        companyId: 0,
        listLoading: false,
        loginType: 0,
        loginType1: {
          type: 0
        },
        accountList: [],
        account: {
          id: '',
          loginName: '',
          nickName: '',
          userName: '',
          phone: '',
          mail: '',
          status: false,
          weixin: '',
          createTime: ''
        },
        userNameSearch: '',
        phoneSearch: '',
        loginNameSearch: ''
      }
    },
    methods: {
      search () {
        this.page = 1
        this.initAccountList()
      },
      // 分页插件查询方法-条数
      handleSizeChange (val) {
        this.pageSize = val
        this.initAccountList()
      },
      // 分页插件查询方法-页数
      handleCurrentChange (val) {
        this.page = val
        this.currentPage = val
        this.initAccountList()
      },
      selsChange: function (sels) {
        this.sels = sels
      },
      // 【删除】按钮事件
      handleDelete (index, row) {
        var ids = []
        ids.push(row.id)
        this.deleteAccount(ids)
      },
      // 【批量删除】按钮事件
      batchDelete () {
        var ids = []
        this.sels.map(item => {
          ids.push(item.id)
        })
        this.deleteAccount(ids)
      },
      // 【删除】、【批量删除】执行方法
      deleteAccount (ids) {
        this.$confirm('确认删除选中商家吗？', '提示', {
          type: 'warning'
        }).then(() => {
          this.$http.post('/smartLight/web/baseAccount/deleteByIds.htm', ids + '|' + this.loginType).then(response => {
            var resBody = response.body
            if (resBody.isSuccess === 0) {
              this.$message({
                showClose: true,
                message: '操作成功',
                type: 'success'
              })
              this.initAccountList()
            } else if (resBody.isSuccess === 2) {
              this.listLoading = false
              sessionOut(this) // session超时处理
            } else {
              this.$message({
                showClose: true,
                message: '操作失败',
                type: 'error'
              })
            }
          })
        }).catch(() => {
        })
      },
      // 初始化分页查询常旅客信息
      initAccountList () {
        this.listLoading = true
        var para = {
          pageNumber: this.page,
          pageSize: this.pageSize,
          type: this.loginType,
          userName: this.userNameSearch,
          phone: this.phoneSearch,
          loginName: this.loginNameSearch,
          op: 'page'
        }
        this.$http.post('/smartLight/web/baseAccount/getList.htm', para).then(response => {
          var resBody = response.body
          this.listLoading = false
          if (resBody.isSuccess === 0) {
            this.total = resBody.result.totalElements
            this.accountList = resBody.result.content
          } else if (resBody.isSuccess === 2) {
            sessionOut(this) // session超时处理
          } else {
            this.$message({
              showClose: true,
              message: resBody.errorMsg,
              type: 'error'
            })
          }
        })
      },
      //      时间格式化
      createTimeStr (row, column) {
        var d = new Date(row.createTime)
        var year = d.getFullYear()
        var month = d.getMonth() + 1
        if (month < 10) {
          month = '0' + month
        }
        var date = d.getDate()
        if (date < 10) {
          date = '0' + date
        }
        var hh = d.getHours()
        if (hh < 10) {
          hh = '0' + hh
        }
        var mm = d.getMinutes()
        if (mm < 10) {
          mm = '0' + mm
        }
        var ss = d.getSeconds()
        if (ss < 10) {
          ss = '0' + ss
        }
        return year + '-' + month + '-' + date + ' ' + hh + ':' + mm + ':' + ss
      }
    },
    mounted () {
      var user = sessionStorage.getItem('user')
      if (user) {
        user = JSON.parse(user)
        this.loginType = user.type
        this.companyId = user.companyId
        this.loginType1.type = user.type
        this.initAccountList()
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  .tabRow
    font-size: 12px;

  .button-align
    float: right;

  .el-dialog--small
    width: 37%;

  .prompt
    color: #ff4949
    line-height: 10px !important;
    display: block;

  #formheight
    margin: 14px 0;
    height: 38px;
    .el-form-item__content
      height: 30px;
      .el-form-item__error
        margin-top: 3px
    .el-input
      height: 30px;
      .el-input__inner
        height: 30px;

  .borderStyle
    .el-input .el-input__inner {
      border-color: #ff4949 !important;
    }

  .cell
    padding-left: 0px !important
    padding-right 0px !important
    overflow: hidden !important
    text-overflow: ellipsis !important
    white-space: nowrap !important
    .el-checkbox {
      padding-left: 15px !important
    }

  #pagination
    background-color: transparent
    .el-input__inner
      width: 120px
</style>
